import {createStore, applyMiddleware, compose} from 'redux';

import promiseMiddleware from '../middlewares/promiseMiddleware'
import rootReducer from '../reducers/root';
import thunkMiddleware from 'redux-thunk';
import {routerReducer, syncHistoryWithStore, routerActions, routerMiddleware} from 'react-router-redux';
import {Router, Route, browserHistory} from 'react-router';
import {composeWithDevTools} from 'redux-devtools-extension';
const enhancer = composeWithDevTools(
    // Middleware you want to use in development:
    applyMiddleware(
        thunkMiddleware,
        routerMiddleware(browserHistory),
        promiseMiddleware({promiseTypeSuffixes: ['PENDING', 'SUCCESS', 'ERROR']})
    )
);


export default function configureStore(initialState) {
    // Note: only Redux >= 3.1.0 supports passing enhancer as third argument.
    // See https://github.com/rackt/redux/releases/tag/v3.1.0
    const store = createStore(rootReducer, initialState, enhancer);
    // Hot reload reducers (requires Webpack or Browserify HMR to be enabled)
    if (module.hot) {
        module.hot.accept('../reducers/root', () =>
            store.replaceReducer(require('../reducers/root')/*.default if you use Babel 6+ */)
        );
    }
    return store;
}

